#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

void solve()
{
	ll x,y,k;
	cin>>x>>y>>k;
	ll ans=y+abs(y-x);
	ll cnt=x;
	if(abs(x-y)<=k) cnt+=abs(x-y);
	else
	{
		cnt=cnt+2*abs(x-y)-k;
	}
	cout<<min(ans,cnt)<<'\n';
}
int main()
{
	IOS;
	int T=1;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

